package com.delaphone.fadmin.action;

import com.delaphone.fadmin.model.FAdmins;
import com.delaphone.fadmin.service.AdminService;
import java.util.ArrayList;
import java.util.List;
import com.delaphone.flocash.web.bean.SelectList;
import com.opensymphony.xwork2.Action;

/**
 *
 * @author trieunx
 */
public class ManageUserAction extends CoreAction {

    private List<FAdmins> admins;
    private AdminService adminService;
    private byte roleId = 0;//all roles
    private int pageNumber = 1;
    private int pageSize = 20;
    private String usN;
    private long totalPages;
    private ArrayList<SelectList> pages;
    private ArrayList<SelectList> roleList;

    public String index() {
        admins = adminService.listAdminUser(roleId, pageNumber, pageSize);
        long total = adminService.findUserRowCount(roleId);
        return Action.INPUT;
    }

    @Override
    public String execute() {
        admins = adminService.listAdminUser(roleId, pageNumber, pageSize);
        long total = adminService.findUserRowCount(roleId);
        if (total == 0) {
            totalPages = 1;
        } else {
            totalPages = ((total - 1) / pageSize) + 1;
        }
        return Action.SUCCESS;
    }

// <editor-fold defaultstate="collapsed" desc="set and get method">
    public AdminService getAdminService() {
        return adminService;
    }

    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

    public ArrayList<SelectList> getPages() {
        pages = new ArrayList<SelectList>();
        for (long i = 1; i <= totalPages; i++) {
            String id = String.valueOf(i);
            // String value="@<a href=/opt/doSearchCustomer.htm>"+id+"</a>";
            pages.add(new SelectList(id, id));

        }
        return pages;
    }

    public void setPages(ArrayList<SelectList> pages) {
        this.pages = pages;
    }

    public ArrayList<SelectList> getRoleList() {
        roleList = new ArrayList<SelectList>();
        roleList.add(new SelectList("0", "All"));
        roleList.add(new SelectList("1", "Administrator"));
        roleList.add(new SelectList("2", "Operator"));
        roleList.add(new SelectList("3", "Reporter"));
        return roleList;
    }

    public void setRoleList(ArrayList<SelectList> roleList) {
        this.roleList = roleList;
    }

    public List<FAdmins> getAdmins() {
        return admins;
    }

    public void setAdmins(List<FAdmins> admins) {
        this.admins = admins;
    }

    public String getUsN() {
        return usN;
    }

    public void setUsN(String usN) {
        this.usN = usN;
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public byte getRoleId() {
        return roleId;
    }

    public void setRoleId(byte roleId) {
        this.roleId = roleId;
    }
    // </editor-fold> 
}
